| Conditions | 4 |
| Total Lines | 25 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | export async function copyToClipboard(event, text: string): Promise<void> { |
||
| 2 | if (event.clipboardData && event.clipboardData.setData) { |
||
| 3 | // IE specific code path to prevent textarea being shown while dialog is visible. |
||
| 4 | return event.clipboardData.setData("Text", text); |
||
| 5 | } |
||
| 6 | if ( |
||
| 7 | document.queryCommandSupported && |
||
| 8 | document.queryCommandSupported("copy") |
||
| 9 | ) { |
||
| 10 | const textarea = document.createElement("textarea"); |
||
| 11 | textarea.textContent = text; |
||
| 12 | textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in MS Edge. |
||
| 13 | document.body.appendChild(textarea); |
||
| 14 | textarea.select(); |
||
| 15 | try { |
||
| 16 | document.execCommand("copy"); // Security exception may be thrown by some browsers. |
||
| 17 | return Promise.resolve(); |
||
| 18 | } catch (ex) { |
||
| 19 | console.warn("Copy to clipboard failed.", ex); |
||
| 20 | return Promise.reject(); |
||
| 21 | } finally { |
||
| 22 | document.body.removeChild(textarea); |
||
| 23 | } |
||
| 24 | } |
||
| 25 | return Promise.reject(); |
||
| 26 | } |
||
| 51 |